import { getDayStartTime, getDayEndTime } from '@/utils'

export default {
  data () {
    return {
      initLoading: false,
      orderList: [],
      accountList: [],
      queryCondition: {
        orderNumber: '',
        billNumber: ''
      },
      dateValue: [],
      cacheCondition: {},
      orderStatus: '',
      orderStatusOption: [
        {
          value: '',
          label: '进行中'
        },
        {
          value: '1200_pay',
          label: '待支付'
        },
        {
          value: '1300_endorse',
          label: '待背书'
        },
        {
          value: '1400_sign',
          label: '待签收'
        }
      ]
    }
  },
  computed: {
    otherCondition () {
      const { dateValue } = this
      return {
        startDate: dateValue && dateValue[0],
        endDate: dateValue && dateValue[1]
      }
    },
    filterList () {
      const { orderNumber, billNumber, startDate, endDate } = this.cacheCondition
      return this.orderList.filter(item => {
        if (this.orderStatus && item.status !== this.orderStatus) {
          return false
        }
        if (orderNumber && item.orderNumber !== orderNumber) {
          return false
        }
        if (billNumber && !item.billNumber.includes(billNumber)) {
          return false
        }
        if (startDate && endDate) {
          const startTime = getDayStartTime(startDate)
          const endTime = getDayEndTime(endDate)
          const { matchTime } = item
          if (matchTime < startTime || matchTime > endTime) {
            return false
          }
        }
        return true
      })
    }
  },
  methods: {
    getList () {},
    search () {
      this.cacheCondition = { ...{}, ...this.queryCondition, ...this.otherCondition }
      this.getList()
    }
  }
}
